home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / bbs / ny_100.zip / NY_JPSRC.ZIP / JACKPOT.CPP < prev    next >
C/C++ Source or Header  |  1995-09-21  |  16KB  |  590 lines

  1. //Include the header file
  2. #include "jackpot.h"
  3.  
  4. //fuction prototypes
  5. unsigned long get_val(unsigned long def, unsigned long max);
  6.   //ny2008 value entering system
  7.  
  8. void strzcpy(char dest[],const char src[], int beg,int end);
  9.   //copy characters from a middle of a string
  10.  
  11. char *ny_un_emu(const char line[],char out[]);
  12.   //remove color codes from line[] and out put to out[]
  13.  
  14. int main(int argc,char *argv[]);
  15.   // main fuction
  16.  
  17. int main(int argc,char *argv[])
  18. {
  19.   FILE *file_handle;          //file handle
  20.   char key;                   //single character for menu choice
  21.   char *char_in_string;       //character pointer used in terminating strings
  22.   unsigned int money;         //money that was bet
  23.   unsigned long jackpot;      //the jackpot
  24.   user_rec urec;              //user record
  25.   unsigned int chance;        //the chance variable ... will store a random num
  26.   unsigned int max_bet;       //maximum bet
  27.   unsigned int set_ch=20000;  //average winable jackpot
  28.   int intval;                 //temporary int variable
  29.   char tmp_str_1[61],tmp_str_2[35];//temporary strings
  30.   char dfile1[74],dfile2[74]; //dropfile names
  31.   ffblk ff;                   //ffblk
  32.   int ans_t,avt_t;            //ANSI?,AVATAR? Boolean values
  33.   int x,x2;                   //for loop counters
  34.   char path[60];              //path to drop files
  35.   int user_num;               //user number
  36.  
  37.  
  38.   //registration (enter you opendoors reg key here)
  39.   strcpy(od_registered_to,"Nobody");
  40.   od_registration_key=0000000000000;
  41.  
  42.   //do not use direct video writes
  43.   directvideo=0;
  44.  
  45.   //include config file
  46.   od_control.od_config_file = INCLUDE_CONFIG_FILE;
  47.   od_control.od_config_filename = "JACKPOT.CFG";
  48.  
  49.   //include multiple personality system
  50.   od_control.od_mps=INCLUDE_MPS;
  51.   od_control.od_nocopyright=TRUE;
  52.  
  53.   //there was not enough arguments passed
  54.   if(argc<4) {
  55.     printf("\n\r\n\rJACKPOT:Not enough arguments\n\r\n\r");
  56.     exit(12);
  57.   }
  58.  
  59.   //argument #1 is the path to the drop files
  60.   strcpy(path,argv[1]);
  61.  
  62.   //get the second argument
  63.   x=2;
  64.  
  65.   //read all arguments and act accordingly
  66.   do {
  67.  
  68.     //game is local (NY2008's generic argument)
  69.     if (strnicmp(argv[x],"-L",2)==0) {
  70.       od_control.od_force_local=TRUE;
  71.  
  72.     //node number (NY2008's generic argument)
  73.     } else if (strnicmp(argv[x],"-N",2)==0) {
  74.       strzcpy(tmp_str_1,argv[x],2,59);
  75.       sscanf(tmp_str_1,"%d",&intval);
  76.       od_control.od_node=intval;
  77.  
  78.     //average jackpot winable size
  79.     } else if (strnicmp(argv[x],"-J",2)==0) {
  80.       strzcpy(tmp_str_1,argv[x],2,59);
  81.       sscanf(tmp_str_1,"%u",&set_ch);
  82.  
  83.     // user number (NY2008's generic argument)
  84.     } else if (strnicmp(argv[x],"-U",2)==0) {
  85.       strzcpy(tmp_str_1,argv[x],2,59);
  86.       sscanf(tmp_str_1,"%d",&user_num);
  87.  
  88.     //use direct writes
  89.     } else if (strnicmp(argv[x],"-DV",3)==0) {
  90.       directvideo=1;
  91.  
  92.     //use a different .CFG file
  93.     } else if (strnicmp(argv[x],"-C",2)==0) {
  94.       strzcpy(od_control.od_config_filename,argv[x],2,59);
  95.     }
  96.  
  97.   //loop for all arguments
  98.   } while ((++x)<=argc);
  99.  
  100.   //do not read any drop files (will be read manually this is for odoors)
  101.   od_control.od_disable|=DIS_INFOFILE;
  102.  
  103.   //get length of path and check weather it includes a trailing slash
  104.   // if not then add it
  105.   x=strlen(path);
  106.   if (path[x-1]!='\\') {
  107.     path[x]='\\';
  108.     path[x+1]=0;
  109.   }
  110.  
  111.   //create drop file names
  112.   sprintf(dfile1,"%su%07d.inf",path,user_num);
  113.   sprintf(dfile2,"%sn%07d.sts",path,od_control.od_node);
  114.  
  115.   //if one or both are not found exit
  116.   if(findfirst(dfile1,&ff,0)!=0 * findfirst(dfile2,&ff,0)!=0) {
  117.     printf("\n\r\n\rJACKPOT:Game drop file(s) not found!\n\r\n\r");
  118.     exit(12);
  119.   }
  120.  
  121.   //open .inf file
  122.   file_handle=fopen(dfile1,"rt");
  123.  
  124.   //get first line (bbs dropfile path)
  125.   fgets(od_control.info_path,59,file_handle);
  126.   //get rid of the \n char in the string and make it 0
  127.   if((char_in_string=strchr(od_control.info_path,'\n'))!=0)
  128.     *char_in_string=0;
  129.  
  130.   //get second line (time limit)
  131.   fgets(tmp_str_1,30,file_handle);
  132.   //read in the value
  133.   sscanf(tmp_str_1,"%d",&od_control.caller_timelimit);
  134.  
  135.   //comport
  136.   fgets(tmp_str_1,30,file_handle);
  137.   sscanf(tmp_str_1,"%d",&od_control.port);
  138.  
  139.   //baud rate
  140.   fgets(tmp_str_1,30,file_handle);
  141.   sscanf(tmp_str_1,"%lu",&od_control.baud);
  142.  
  143.   //terminal emulation
  144.   fgets(tmp_str_1,30,file_handle);
  145.   //get rid of the \n char in the string and make it 0
  146.   if((char_in_string=strchr(tmp_str_1,'\n'))!=0)
  147.     *char_in_string=0;
  148.  
  149.   //set avt_t and ans_t according to tmp_str_1
  150.   //ansi
  151.   if(strcmp(tmp_str_1,"ANSI")==0) {
  152.     ans_t=TRUE;
  153.     avt_t=FALSE;
  154.   //avatar
  155.   } else if(strcmp(tmp_str_1,"AVATAR")==0) {
  156.     ans_t=TRUE;
  157.     avt_t=TRUE;
  158.   //ascii
  159.   } else {
  160.     ans_t=FALSE;
  161.     avt_t=FALSE;
  162.   }
  163.  
  164.   //get players location
  165.   fgets(od_control.user_location,25,file_handle);
  166.   //get rid of the \n char in the string and make it 0
  167.   if((char_in_string=strchr(od_control.user_location,'\n'))!=0)
  168.     *char_in_string=0;
  169.  
  170.   //is fossil used?
  171.   fgets(tmp_str_1,30,file_handle);
  172.   //get rid of the \n char in the string and make it 0
  173.   if((char_in_string=strchr(tmp_str_1,'\n'))!=0)
  174.     *char_in_string=0;
  175.  
  176.   //fossil used
  177.   if(strcmp(tmp_str_1,"FOSSIL")==0) {
  178.     od_control.od_com_method=COM_FOSSIL;
  179.  
  180.   //fossil not used read the comm settings
  181.   } else {
  182.     od_control.od_com_method=COM_INTERNAL;
  183.  
  184.     //get com address
  185.     fgets(tmp_str_1,30,file_handle);
  186.     sscanf(tmp_str_1,"%d",&od_control.od_com_address);
  187.  
  188.     //get irq
  189.     fgets(tmp_str_1,30,file_handle);
  190.     sscanf(tmp_str_1,"%d",&intval);
  191.     od_control.od_com_irq=intval;
  192.  
  193.     //use FIFO?
  194.     fgets(tmp_str_1,30,file_handle);
  195.     //get rid of the \n char in the string and make it 0
  196.     if((char_in_string=strchr(tmp_str_1,'\n'))!=0)
  197.       *char_in_string=0;
  198.  
  199.     //no fifo
  200.     if(strcmp(tmp_str_1,"NOFIFO")==0)
  201.       od_control.od_com_no_fifo=TRUE;
  202.  
  203.     //use fifo
  204.     else
  205.       od_control.od_com_no_fifo=FALSE;
  206.  
  207.     //fifo trigger size
  208.     fgets(tmp_str_1,30,file_handle);
  209.     sscanf(tmp_str_1,"%d",&intval);
  210.     od_control.od_com_fifo_trigger=intval;
  211.  
  212.     //recieve buffer
  213.     fgets(tmp_str_1,30,file_handle);
  214.     sscanf(tmp_str_1,"%u",&od_control.od_com_rx_buf);
  215.  
  216.     //transmit buffer
  217.     fgets(tmp_str_1,30,file_handle);
  218.     sscanf(tmp_str_1,"%u",&od_control.od_com_tx_buf);
  219.   }
  220.  
  221.   //close the .inf file
  222.   fclose(file_handle);
  223.  
  224.   //open the .sts file
  225.   file_handle=fopen(dfile2,"rb");
  226.  
  227.   //read in the user record
  228.   fread(&urec,sizeof(user_rec),1,file_handle);
  229.  
  230.   //close the .sts file
  231.   fclose(file_handle);
  232.  
  233.   //destroy emulation codes and put it in tmp_str_2
  234.   ny_un_emu(urec.name,tmp_str_2);
  235.  
  236.   //store this in user name so that the handle will display first and
  237.   //bbsname second. If you read any bbs drop files be sure to change it
  238.   //back before you exit.
  239.   sprintf(tmp_str_1,"%s (%s)",tmp_str_2,urec.bbsname);
  240.   strcpy(od_control.user_name,tmp_str_1);
  241.  
  242.   //display the copyright message (it won't really show but it will be there)
  243.   od_printf("`bright`New York 2008 Jackpot IGM, FREEWARE!\n\r(c) Copyright 1995, George Lebl - All rights Reserved\n\r");
  244.  
  245.   //se the ansi and avatar values
  246.   od_control.user_ansi=ans_t;
  247.   od_control.user_avatar=avt_t;
  248.  
  249.   //check if another node is using the IGM
  250.   if(findfirst("JACKPOT.USD",&ff,0)!=0) {
  251.     file_handle=fopen("JACKPOT.USD","wt");
  252.     fclose(file_handle);
  253.  
  254.   //if it is exit
  255.   } else {
  256.     od_printf("\n\r`bright red`T`red`he IGM is used by another node!\n\r`bright red`T`red`his IGM is not multinode capable!\n\r`bright red`C`red`ome back later!\n\r\n\r`bright red`Smack [Enter] to countinue:");
  257.     od_get_answer("\n\r");
  258.     od_exit(10,FALSE);
  259.   }
  260.  
  261.   //check if the dat file is there
  262.   //if not create it and make the jackpot 100
  263.   if(findfirst("JACKPOT.DAT",&ff,0)!=0) {
  264.     jackpot=100;
  265.     file_handle=fopen("JACKPOT.DAT","wt");
  266.     fprintf(file_handle,"100");
  267.     fclose(file_handle);
  268.  
  269.   //if yes read in the value
  270.   } else {
  271.     file_handle=fopen("JACKPOT.DAT","rt");
  272.     fscanf(file_handle,"%lu",&jackpot);
  273.     fclose(file_handle);
  274.   }
  275.  
  276.   //this is where the main menu is drawn
  277.   main_menu:
  278.  
  279.   //if the user would not have clear clearing it will push the menu a bit down
  280.   od_printf("\n\r\n\r");
  281.  
  282.   //clear screen
  283.   od_clr_scr();
  284.  
  285.   //display the menu
  286.   od_printf("`bright red`J`red`ackpot IGM for `bright green`NY2008`red`!\n\r\n\r");
  287.   od_printf("`bright white`The jackpot is: `flashing bright red`%lu\n\r\n\r",jackpot);
  288.   od_printf("`bright red`B `red`- `bright red`B`red`et\n\r");
  289.   od_printf("`bright red`Q `red`- `bright red`Q`red`uit\n\r\n\r");
  290.   od_printf("`bright blue`E`blue`nter `bright blue`Y`blue`er `bright blue`C`blue`ommand (`bright blue`%d `blue`mins)`bright blue`>`bright`",od_control.caller_timelimit);
  291.  
  292.   //get the user response
  293.   key=od_get_answer("BQ");
  294.  
  295.   //display it
  296.   od_putch(key);
  297.  
  298.   //if user chose to quit .. quit
  299.   if(key=='Q') {
  300.     od_printf("\n\r\n\r`bright red`L`red`eaving the `flashing bright red`JACKPOT\n\r\n\r");
  301.  
  302.     //the game is not used anymore
  303.     remove("JACKPOT.USD");
  304.     od_exit(10,FALSE);
  305.  
  306.   //if user is betting
  307.   } else {
  308.  
  309.     //warn about no money
  310.     if(urec.money==0)
  311.       od_printf("\n\r\n\r`bright red`Y`red`a ain't got no money on hand!");
  312.  
  313.     //because the highest bet is half the average jackpot win size
  314.     //make it that unless the user's got less money
  315.     if(urec.money>(int)(set_ch/2))
  316.       chance=(int)(set_ch/2);
  317.     else
  318.       chance=urec.money;
  319.  
  320.     //display prompt
  321.     od_printf("\n\r\n\r`bright green`H`green`ow much`green` (`bright blue`Enter`green`=`bright green`[0]`green`, `bright blue`M`green`=max `bright green`%u`green`):",chance);
  322.  
  323.     //use the ny value entering system to get the value
  324.     money=get_val(0,chance);
  325.  
  326.     //if user bet 0 goto mainmenu
  327.     if(money==0) goto main_menu;
  328.  
  329.     //seed the random number generator
  330.     randomize();
  331.  
  332.     //make it look like there's something going on
  333.     od_printf("\n\r\n\r`bright red`I`red`t's turning - `bright`");
  334.  
  335.     //turn around 3 digit numbers for a while
  336.     for(x=0;x<20;x++) {
  337.       od_printf("%3d\b\b\b",random(1000));
  338.       for(x2=0;x2<200;x2++)
  339.     od_kernel();
  340.     }
  341.  
  342.     // add the money betted to jackpot
  343.     jackpot+=money;
  344.  
  345.     //take off users money that he bet
  346.     urec.money-=money;
  347.  
  348.     //set the chance of winning
  349.     chance=(unsigned int)random(set_ch/2) * 2;
  350.  
  351.     //check if user won
  352.     if(chance<money) {
  353.  
  354.       //put WON over the 3 digit numbers
  355.       od_printf("WON");
  356.  
  357.       //take a 10% tax
  358.       jackpot=(jackpot*90)/100;
  359.  
  360.       //display that user had won
  361.       od_printf("\n\r\n\r`bright red`Y`red`ou have won %lu!\n\r`bright red`Y`red`ou had to pay 10\% tax though!",jackpot);
  362.  
  363.   /*****this routine adds money but checks for overflow*****/
  364.   /**/    unsigned long med;                             /**/
  365.   /**/                                                   /**/
  366.   /**/    med=ULONG_MAX-jackpot;                         /**/
  367.   /**/    if (med<=urec.money)                           /**/
  368.   /**/      urec.money=ULONG_MAX;                        /**/
  369.   /**/    else                                           /**/
  370.   /**/      urec.money+=jackpot;                         /**/
  371.   /*********************************************************/
  372.  
  373.       //display the enter prompt
  374.       od_printf("\n\r\n\r`bright red`Smack [Enter] to continue:");
  375.  
  376.       //wait for enter
  377.       od_get_answer("\n\r");
  378.  
  379.       //open the jackpot dat file
  380.       file_handle=fopen("JACKPOT.DAT","wt");
  381.  
  382.       //put a hundred in
  383.       fprintf(file_handle,"100");
  384.  
  385.       //close the file
  386.       fclose(file_handle);
  387.  
  388.       //display leaving message
  389.       od_printf("\n\r\n\r`bright red`L`red`eaving the `flashing bright red`JACKPOT\n\r\n\r");
  390.  
  391.       //others can use the igm
  392.       remove("JACKPOT.USD");
  393.  
  394.       //write out the user record into the .sts file for NY2008 to read
  395.       file_handle=fopen(dfile2,"wb");
  396.       fwrite(&urec,sizeof(user_rec),1,file_handle);
  397.       fclose(file_handle);
  398.  
  399.       //exit
  400.       od_exit(10,FALSE);
  401.  
  402.     //if user lost
  403.     } else {
  404.  
  405.       //put LOST over the 3 digit numbers
  406.       od_printf("LOST");
  407.  
  408.       //display message
  409.       od_printf("\n\r\n\r`bright red`Y`red`ou have `bright`LOST!");
  410.       od_printf("\n\r\n\r`bright red`Smack [Enter] to continue:");
  411.  
  412.       //wait for enter
  413.       od_get_answer("\n\r");
  414.  
  415.       //write the jackpot into the data file
  416.       file_handle=fopen("JACKPOT.DAT","wt");
  417.       fprintf(file_handle,"%lu",jackpot);
  418.       fclose(file_handle);
  419.  
  420.       //exitting message
  421.       od_printf("\n\r\n\r`bright red`L`red`eaving the `flashing bright red`JACKPOT\n\r\n\r");
  422.  
  423.       //others can use the igm
  424.       remove("JACKPOT.USD");
  425.  
  426.       //write out the .sts for ny2008 to read
  427.       file_handle=fopen(dfile2,"wb");
  428.       fwrite(&urec,sizeof(user_rec),1,file_handle);
  429.       fclose(file_handle);
  430.  
  431.       //exit
  432.       od_exit(10,FALSE);
  433.     }
  434.   }
  435.   return(0);
  436. }
  437.  
  438. unsigned long    //value input system
  439. get_val(unsigned long def, unsigned long max)
  440. {
  441. //this function gets a number from the user just like ny2008 does
  442. //max is the maximim value user can enter
  443. //def is the default value if user presses enter
  444.  
  445.   char input_s[30];         //input string
  446.   unsigned long intval=0;   //temp value
  447.   int cnt=0;                //loop counter
  448.  
  449.  
  450.   Again:                    //do again if neccesary
  451.  
  452.   //set input string to spaces
  453.   strset(input_s,' ');
  454.  
  455.   //get first digit
  456.   input_s[0]= od_get_answer("0123456789M\n\r");
  457.  
  458.   //user wants maximum
  459.   if (input_s[0]=='M') {
  460.     od_printf("%lu\n\r",max);
  461.     return(max);
  462.   }
  463.  
  464.   //user wants default
  465.   else if (input_s[0]=='\n' || input_s[0]=='\r') {
  466.     od_printf("%lu\n\r",def);
  467.     return(def);
  468.   }
  469.  
  470.   //print out the digit
  471.   od_printf("%c",input_s[0]);
  472.  
  473.   //get all other digits
  474.   cnt=0;
  475.   while (1) {
  476.     //only 30 digits allowed
  477.     if (cnt<29)
  478.       cnt++;
  479.     else
  480.       od_printf("\b");
  481.  
  482.     //get a digit
  483.     input_s[cnt]=od_get_answer("0123456789\n\r\b");
  484.  
  485.     //if enter that is the value we want
  486.     if (input_s[cnt]=='\n' || input_s[cnt]=='\r') {
  487.       input_s[cnt]=' ';
  488.       sscanf(input_s,"%lu",&intval);
  489.  
  490.       //the value entered was more than the max value so truncate it
  491.       if (intval>max) {
  492.     do {
  493.       od_printf("\b \b");
  494.       cnt--;
  495.     } while (cnt>0);
  496.     intval=max;
  497.     od_printf("%lu",max);
  498.       }
  499.  
  500.       //print an enter
  501.       od_printf("\n\r");
  502.  
  503.       //get out of the loop
  504.       break;
  505.     }
  506.  
  507.     //print the digit
  508.     od_printf("%c",input_s[cnt]);
  509.  
  510.     //it was backspace
  511.     if (input_s[cnt]=='\b') {
  512.       od_printf(" \b");
  513.       input_s[cnt]=' ';
  514.       cnt--;
  515.       input_s[cnt]=' ';
  516.       cnt--;
  517.       if (cnt == -1) break;
  518.     }
  519.   }
  520.   //if all deleted goto the beginning
  521.   if (cnt == -1) goto Again;
  522.  
  523.   //return the value
  524.   return(intval);
  525. }
  526.  
  527. /*copy end chars beginning from beg to dest*/
  528. /*similiar to strncpy*/
  529. void
  530. strzcpy(char dest[],const char src[], int beg,int end)
  531. {
  532. //dest is the source, src is the cource
  533.  
  534.   int cnt=0; //loop counter
  535.  
  536.   //begin loop
  537.   do {
  538.     //copy
  539.     dest[cnt]=src[beg];
  540.     beg++;
  541.     cnt++;
  542.   //until end characters are copied
  543.   } while (cnt<=end && src[cnt]!=0);
  544.  
  545.   //end the string
  546.   dest[cnt]=0;
  547. }
  548.  
  549. //remove the ny color codes from a string
  550. char
  551. *ny_un_emu(const char line[],char out[])
  552. {
  553. //line is input, out is output
  554.  
  555.   int cnt;   //real pos
  556.   int len;   //pos in out
  557.  
  558.   len=0; //set out pos to 0
  559.  
  560.   //loop for every char in line
  561.   for(cnt=0;line[cnt]!=0;cnt++) {
  562.  
  563.     //if '`' found remove color code
  564.     if(line[cnt]=='`') {
  565.       cnt++;
  566.  
  567.       //end of string
  568.       if(line[cnt]==0) {
  569.     out[len]=0;
  570.     return(out);
  571.       //not a color code but a single '`'
  572.       } else if(line[cnt]=='`') {
  573.     out[len]='`';
  574.     len++;
  575.       }
  576.  
  577.     //'`' not found
  578.     } else {
  579.       out[len]=line[cnt];
  580.       len++;
  581.     }
  582.   }
  583.  
  584.   //end the string
  585.   out[len]=0;
  586.  
  587.   //return the pointer to out
  588.   return(out);
  589. }
  590.